
#include <iostream>
using namespace std;
int duplicationInArray(int arr[],int length)
{
	int idx = 0;
	while(idx < length)
	{
		if(arr[idx] == idx)
		{
			++idx;
			continue;
		}
		else
		{
			if(arr[arr[idx]] == arr[idx])
				return arr[idx];
			else
			{
				cout<<arr[arr[idx]]<<" , "<<arr[idx]<<endl;
				int temp = arr[arr[idx]];
				arr[arr[idx]] = arr[idx];
				arr[idx] = temp;
			}
		}
	}
	return -1;
}

int main()
{
	int arr[] = {2,3,1,0,2,5,3};
	cout<<duplicationInArray(arr,7)<<endl;

	return 0;
}